﻿using System;
using System.Globalization;
using Cesave.DistributedServices.PermisosModule.WindowsHost.Resources;
using Cesave.DistributedServices.PermisosModule.WindowsHost.ViewModelBase;
using Cesave.DistributedServices.PermisosModule.WindowsHost.Views.Catalogs.Ciclos;

namespace Cesave.DistributedServices.PermisosModule.WindowsHost.ViewModels.Catalogs.Ciclos
{
	/// <summary>
	/// 
	/// </summary>
	public partial class CiclosViewModel
		: ObservableObject
	{
		#region Private properties

		/// <summary>
		/// 
		/// </summary>
		private CiclosView _ciclosView;

		#endregion

		#region Constructor
		
		/// <summary>
		/// 
		/// </summary>
		/// <param name="ciclosView"></param>
		public CiclosViewModel(CiclosView ciclosView)
		{
			if (ciclosView == null)
				throw new ArgumentNullException("ciclosView");
			_ciclosView = ciclosView;
			WireUpEvents();
			InitModels();
		}

		#endregion

		#region Event methods

		/// <summary>
		/// 
		/// </summary>
		private void WireUpEvents()
		{
			PropertyChanged += CiclosViewModel_PropertyChanged;
			_ciclosView.Load += LoadView;
			_ciclosView.closeButton.Click += CloseView;
			_ciclosView.newButton.Click += AddNewCiclo;
			_ciclosView.bindingNavigatorAddNewItem.Click += AddNewCiclo;
			_ciclosView.bindingNavigatorDeleteItem.Click += DeleteCiclo;
			_ciclosView.saveButton.Click += SaveCiclo;
			_ciclosView.cicloBindingNavigatorSaveItem.Click += SaveCiclo;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void LoadView(object sender, EventArgs e)
		{
			_ciclosView.Text = string.Format(
				CultureInfo.InvariantCulture,
				WindowTitles.CiclosWindowTitle
			);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void CloseView(object sender, EventArgs e)
		{
			_ciclosView.Close();
		}

		#endregion

		#region Private methods

		/// <summary>
		/// 
		/// </summary>
		private void InitModels()
		{
			LoadCiclos();
		}

		/// <summary>
		/// 
		/// </summary>
		private void FocusDefaultControl()
		{
			_ciclosView.ActiveControl = _ciclosView.nombreUltraTextEditor;
		}

		/// <summary>
		/// 
		/// </summary>
		private void StartWaiting()
		{
			_ciclosView.WaitingBar.StartWaiting();
		}

		/// <summary>
		/// 
		/// </summary>
		private void EndWaiting()
		{
			_ciclosView.WaitingBar.EndWaiting();
		}

		#endregion

	}
}
